package com.hawthorn.admin.controller;

import com.hawthorn.admin.feign.HelloFeignService;
import com.hawthorn.platform.context.ContextHolder;
import com.hawthorn.platform.ret.RestResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

/**
 * @copyright: Copyright (c) 2021 andyten
 * <p></p>
 * @remark: todo
 * @author: andyten@tom.com | xukaixing@hotmail.com
 * @created: 4/5/21 6:02 PM
 * @lasted: 4/5/21 6:02 PM
 * @version v1.0.1
 */
@Api(tags = {"demo-hello-controller"})
@RestController
@RequestMapping("/hello")
@Slf4j
@RefreshScope
public class HelloController
{
  @Autowired
  HelloFeignService helloFeignService;
  //
  // @Autowired
  // private RedisMyClient redisMyClient;
  //
  // @Value("${hello:nothing}")
  // private String hello;
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 4/5/21 11:07 AM
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "/hello->loadHello", notes = "读取配置中心内容")
  // @ApiImplicitParams({
  // })
  // @GetMapping(value = "/loadHello")
  // public RestResult loadConfig()
  // {
  //   log.info("====== load config ======");
  //   log.info("redis:{}", redisMyClient.hGet("cache:dict:sf", "val"));
  //   return RestResult.success(this.hello);
  // }
  //

  /**
   * @author: andyten@tom.com | xukaixing@hotmail.com
   * @date: 2020/10/28 4:04 下午
   * @version: 1.0.1
   */
  @ApiOperation(value = "feign->/hello->sayHello", notes = "feign接口调用demo")
  @GetMapping(value = "/feign/sayHello")
  public RestResult sayHello()
  {
    log.info("====== feign 调用 ======");
    RequestContextHolder.currentRequestAttributes().setAttribute("name", "YourBatman", RequestAttributes.SCOPE_REQUEST);
    ContextHolder.setUserAccount("admin");
    log.info(ContextHolder.getUserAccount());
    return helloFeignService.sayHello();
  }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/13 2:56 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->全部用户信息", notes = "查询全部用户信息服务 不带参数")
  // @GetMapping(value = "/selectUsersAll")
  // public List<SysUserDTO> selectUsersAll()
  // {
  //   List<SysUserDTO> users = sysUserService2.selectNoPage();
  //   log.info("====== show userlist ====== ");
  //   users.forEach(System.out::println);
  //   return users;
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/19 2:36 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->全部用户信息(物理分页)", notes = "查询全部用户信息服务 带分页")
  // @ApiImplicitParams({
  //
  // })
  // @GetMapping(value = "/selectUsersByPage")
  // public IPage<Map<String, Object>> selectUsersByPage()
  // {
  //   int pageNum = 1;
  //   int pageSize = 2;
  //   Page<Map<String, Object>> page = new Page<Map<String, Object>>(pageNum, pageSize);
  //
  //   IPage<Map<String, Object>> users = sysUserService2.selectByPage(page);
  //   return users;
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/19 2:36 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->全部用户信息(物理分页带where条件)", notes = "查询全部用户信息服务 带分页")
  // @ApiImplicitParams({
  //
  // })
  // @GetMapping(value = "/select")
  // public IPage<SysUserDTO> select()
  // {
  //   int pageNum = 1;
  //   int pageSize = 2;
  //   Page<SysUserDTO> page = new Page<>(pageNum, pageSize);
  //   QcBean qc = new QcBean();
  //   qc.setId("delFlag");
  //   qc.setOp("=");
  //   qc.setDs("del_flag");
  //   qc.setValue("0");
  //   QcBean qc2 = new QcBean();
  //   qc2.setId("nickName");
  //   qc2.setOp("=");
  //   qc2.setDs("nick_name");
  //   qc2.setValue("%test%");
  //   HashMap<String, QcBean> hm = new HashMap<>();
  //   hm.put(qc.getId(), qc);
  //   hm.put(qc2.getId(), qc2);
  //   return sysUserService2.select(page, hm);
  // }
  //
  // @Autowired
  // SysUserService2 sysUserService2;
  //
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/13 9:21 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->全部用户信息(Privider方式)", notes = "查询全部用户信息服务 使用Privider方式 无须配置mapper xml")
  // @ApiImplicitParams({
  //
  // })
  // @GetMapping(value = "/selectUsersAllPrivider")
  // public List<SysUserDTO> selectUsersAllPrivider()
  // {
  //   List<SysUserDTO> users = sysUserService2.selectAllPrivider();
  //   return users;
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/13 6:25 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->按状态查询用户", notes = "按状态查询用户信息服务 带参数status")
  // @ApiImplicitParams({
  //     @ApiImplicitParam(name = "status", value = "状态", required = true, dataType = "Byte", dataTypeClass = Byte.class, paramType = "query")
  // })
  // @GetMapping(value = "/selectUsersByStatus")
  // public List<SysUserDTO> selectUsersByStatus(@RequestParam(value = "status", required = true) Byte status)
  // {
  //   List<SysUserDTO> users = sysUserService2.selectAllByStatus(status);
  //   log.info("====== show userlist ====== ");
  //   users.forEach(x -> log.info(String.valueOf(x)));
  //   return users;
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/13 6:31 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "查询->按属性查询用户", notes = "按属性查询用户信息服务")
  // @ApiImplicitParams({
  //     @ApiImplicitParam(name = "fieldName", value = "属性名", required = true, dataType = "String", dataTypeClass = String.class, paramType = "query"),
  //     @ApiImplicitParam(name = "fieldValue", value = "属性值", required = false, dataType = "String", dataTypeClass = String.class, paramType = "query")
  // })
  // @GetMapping(value = "/selectUsersByField")
  // public List<SysUserDTO> selectUsersByField(@RequestParam(value = "fieldName") String fieldName, @RequestParam(value = "fieldValue") String fieldValue)
  // {
  //   return sysUserService2.selectAllByField(fieldName, fieldValue);
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/14 12:03 上午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "保存->用户新增", notes = "用户新增服务")
  // @ApiImplicitParams({
  // })
  // @PutMapping(value = "/insertUser")
  // public boolean insertUser()
  // {
  //   sysUserService2.insertUser();
  //   //sysUserService2.insertUser();
  //   //sysUserService.insertUser2();
  //   //sysUserService.insertUser();
  //   return true;
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/17 10:37 上午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "保存->用户更新", notes = "用户更新服务")
  // @ApiImplicitParams({
  // })
  // @PostMapping(value = "/updateUser")
  // public void updateUser()
  // {
  //   SysUserDTO u = sysUserService2.updateUser();
  //   //sysUserService2.insertUser();
  //   //sysUserService.insertUser2();
  //   //sysUserService.insertUser();
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/21 3:19 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "保存->用户更新(带乐观锁)", notes = "用户更新服务")
  // @ApiImplicitParams({
  //
  // })
  // @PostMapping(value = "/updateUserByVersion")
  // public void updateUserByVersion()
  // {
  //   SysUserDTO u = sysUserService2.updateUserByVersion();
  //   //sysUserService2.insertUser();
  //   //sysUserService.insertUser2();
  //   //sysUserService.insertUser();
  // }
  //
  // /**
  //  * @author: andyten@tom.com | xukaixing@hotmail.com
  //  * @date: 2020/8/21 1:13 下午
  //  * @version: 1.0.1
  //  */
  // @ApiOperation(value = "保存->用户删除", notes = "用户删除服务")
  // @ApiImplicitParams({
  //
  // })
  // @DeleteMapping(value = "/deleteAllUser")
  // public void deleteAll()
  // {
  //   sysUserService2.deleteAll();
  //   //sysUserService2.insertUser();
  //   //sysUserService.insertUser2();
  //   //sysUserService.insertUser();
  // }
}
